#pragma once
#include<iostream>
#include<unistd.h>
#include<sys/socket.h>
#include<string>

class Uint
{
public:
     static bool cutHttpHeader(const std::string&line,std::string &key,std::string &value,std::string step)
    {
        size_t pos = line.find(step);
        if(pos != std::string::npos)
        {
            //找到了；
            key = line.substr(0,pos);
            value = line.substr(pos+step.size());
            return true;
        }
        return false;

    }
    //读取一行；
   static int getHttpLine(int sock, std::string &out)
        {
            char ch = 'X';
            while(ch != '\n'){
                ssize_t s = recv(sock, &ch, 1, 0);
                if(s > 0){
                    if(ch == '\r'){
                        recv(sock, &ch, 1, MSG_PEEK);
                        if(ch == '\n'){
                            //把\r\n->\n
                            //窥探成功，这个字符一定存在
                            recv(sock, &ch, 1, 0);
                        }
                        else{
                            ch = '\n';
                        }
                    }
                    //1. 普通字符
                    //2. \n
                    out.push_back(ch);
                }
                else if(s == 0){
                    return 0;
                }
                else{
                    return -1;
                }
            }
            return out.size();
        }
            
    
};

